﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using WpfWordsLearner.Helper;
using WpfWordsLearner.Model;
using System.Windows;

namespace WpfWordsLearner.ViewModels
{
	public class AddWordsViewModel : BaseViewModel
	{
		public AddWordsViewModel()
		{
			m_model = new WordsModel();
		}

		private WordsModel m_model = null;

		public ICommand ClickCommand { get { return new BaseCommand(Click); } }

		private void Click()
		{
			if (WordsManager.Instance.AddWord(m_model.EnglishWord, m_model.Translate))
				ShowMessageBox("Word added");
			else
				ShowMessageBoxError("Fail to add word");

			Window wind = App.Current.Windows.Cast<Window>().SingleOrDefault(x => x.IsActive);
			if (wind != null)
			{
				wind.DialogResult = true;
				wind.Close();
			}
		}

		public WordsModel Model
		{
			get { return m_model; }
			set
			{
				m_model = value;
				OnPropertyChanged(() => Model);
			}
		}


		public ICommand ClickCommand2 { get { return new BaseCommand(ClickCancel); } }

		private void ClickCancel()
		{
			Window wind = App.Current.Windows.Cast<Window>().SingleOrDefault(x => x.IsActive);
			if (wind != null)
				wind.Close();
		}
	}
}
